﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace UserStatus
{
    [DefaultProperty("Text")]
    [ToolboxData("<{0}:UserStatus runat=server></{0}:UserStatus>")]
    public class UserStatus : WebControl
    {
        [Bindable(true)]
        [Category("Appearance")]
        [DefaultValue("")]
        [Localizable(true)]
        public string Username
        {
            get
            {
                String s = (String)ViewState["Username"];
                return ((s == null) ? String.Empty : s);
            }

            set
            {
                ViewState["Username"] = value;
            }
        }

        public string img_url
        {
            get
            {
                String s = (String)ViewState["img_url"];
                return ((s == null) ? String.Empty : s);
            }
            set
            {
                ViewState["img_url"] = value;
            }
        }        

        protected override void RenderContents(HtmlTextWriter output)
        {
            String output_string;

            if (Username.CompareTo("") != 0)
            {
                output_string = "Welcome <strong><em>" + Username + "</em></strong>";
                output_string += "&nbsp;<a href='Account.aspx'><img style='width:30px; height:30px'";
                output_string += " src='" + img_url + "'/></a> | <a href='Logout.aspx'>Logout</a>";
            }
            else
            {
                output_string = "<a href='Registration.aspx'>Register</a> | ";
                output_string += "<a href='Login.aspx'>Login</a>";
            }

            output.Write(output_string);
        }
    }
}
